home *** CD-ROM | disk | FTP | other *** search
- Path: news.voyager.net!news
- From: David Wade <dwade@vixa.voyager.net>
- Newsgroups: comp.lang.c++
- Subject: File I/O using fwrite()
- Date: Wed, 17 Apr 1996 20:31:44 -0400
- Organization: The Game Room
- Message-ID: <31758D70.1D38@vixa.voyager.net>
- NNTP-Posting-Host: lans234.dial.voyager.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (Win95; I)
-
- HELP!!! I am having a major problem getting random access file routines
- to work properly. For some reason, no matter what I do the information
- is always written at the end of the file instead of where I want it to
- replace... All I need to do is update a record in a potentailly large
- file, and I can't load the entire file and re-write it to do it. If
- anyone sees what I am doing wrong, or has a possible solution using
- other means, I would greatly appreciate the info. The funtion looks
- like this:
-
- f=_fsopen(".\\data\\weapons.dat", "ab+", SH_DENYNONE);
- if(f == NULL)
- {
- printf("ERROR!");
- exit(1);
- };
- rewind(f);
- fseek(f,(item_data.reference-1)*sizeof(item_struct),SEEK_SET);
- fwrite(&item_data, sizeof(item_struct), 1, f);
- fclose(f);
-
-
- The struct is of type item_struct, and item_data is an instance of that
- struct.
-
- If anyone can help, I would greatly appreciate it. Thanks
-
- Mark Roberts
-